package com.ddpt.platform.common.util.excel;

import com.alibaba.excel.EasyExcel;
import com.ddpt.platform.common.base.BizEntity;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ExcelReaderUtil {

    public static void readMap(InputStream inputStream, ExcelReaderCallBack<Map<String,String>> callBack){
        readMap(1,inputStream,callBack);
    }

    public static void readMap(int readMaxSize, InputStream inputStream,ExcelReaderCallBack<Map<String,String>> callBack){
        EasyExcel.read(inputStream, ReadExcelMapListener.builder(readMaxSize, callBack)).sheet().doRead();
    }

    public static void readMap(int readMaxSize, InputStream inputStream, Set<Integer> skipRow, ExcelReaderCallBack<Map<String, String>> callBack) {
        EasyExcel.read(inputStream, ReadExcelMapListener.builder(readMaxSize, skipRow, callBack)).sheet().doRead();
    }

    public static <T> void readBean(InputStream inputStream,ExcelReaderCallBack<T> callBack){
        readBean(1, inputStream, callBack);
    }

    public static <T> void readBean(int readMaxSize, InputStream inputStream,ExcelReaderCallBack<T> callBack){
        EasyExcel.read(inputStream, ReadExcelBeanListener.builder(readMaxSize, callBack)).sheet().doRead();
    }

    public static <T> void readBean(int readMaxSize, InputStream inputStream, Set<Integer> skipRow, ExcelReaderCallBack<T> callBack) {
        EasyExcel.read(inputStream, ReadExcelBeanListener.builder(readMaxSize, skipRow, callBack)).sheet().doRead();
    }

    public static void main(String[] args) throws FileNotFoundException {

        ExcelReaderUtil.readBean(10,new FileInputStream(new File("D://test.xlsx")),new ExcelReaderCallBack<BizEntity>() {
            @Override
            public void callBack(List<BizEntity> data) {

            }
        });



    }
}
